<?php

	// TITLE: Event_detail AUTO MODEL
	// FILE: scaffolding/model/event_detail.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createEventDetail = function($con, $eventDetail) {
		$sql = 'INSERT INTO event_detail (id, event_id, title, description, interest_id, max_head_count, hours_duration) VALUES (';
		$sql .= $event_detail->getId() . ', ';
		$sql .= $event_detail->getEventId() . ', ';
		$sql .= $event_detail->getTitle() . ', ';
		$sql .= $event_detail->getDescription() . ', ';
		$sql .= $event_detail->getInterestId() . ', ';
		$sql .= $event_detail->getMaxHeadCount() . ', ';
		$sql .= $event_detail->getHoursDuration() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readEventDetail = function($con, $id) {
		$sql = 'SELECT * FROM event_detail WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$eventDetail = new EventDetail();
			$eventDetail->setId(result[0]);
			$eventDetail->setEventId($dbio->select($readEvent(result[1])));
			$eventDetail->setTitle(result[2]);
			$eventDetail->setDescription(result[3]);
			$eventDetail->setInterestId($dbio->select($readInterest(result[4])));
			$eventDetail->setMaxHeadCount(result[5]);
			$eventDetail->setHoursDuration(result[6]);
		} else {
			$eventDetail = false;
		}
		return $eventDetail;
	};

	$updateEventDetail = function($con, $eventDetail) {
		$sql = 'UPDATE event_detail SET ';
		$sql .= 'id = ' . $event_detail->getId() . ', ';
		$sql .= 'event_id = ' . $event_detail->getEventId() . ', ';
		$sql .= 'title = ' . $event_detail->getTitle() . ', ';
		$sql .= 'description = ' . $event_detail->getDescription() . ', ';
		$sql .= 'interest_id = ' . $event_detail->getInterestId() . ', ';
		$sql .= 'max_head_count = ' . $event_detail->getMaxHeadCount() . ', ';
		$sql .= 'hours_duration = ' . $event_detail->getHoursDuration() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteEventDetail = function($con, $id) {
		$sql = 'DELETE FROM event_detail WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listEventDetail = function($con) {
		$sql = 'SELECT * FROM event_detail';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$eventDetails = array();
			while ($result = mysqli_fetch_array($results)) {
				$eventDetail = new EventDetail();
				$eventDetail->setId(result[0]);
				$eventDetail->setEventId($dbio->select($readEvent(result[1])));
				$eventDetail->setTitle(result[2]);
				$eventDetail->setDescription(result[3]);
				$eventDetail->setInterestId($dbio->select($readInterest(result[4])));
				$eventDetail->setMaxHeadCount(result[5]);
				$eventDetail->setHoursDuration(result[6]);
				$eventDetails[] = eventDetail;
			}// end while
		} else {
			$eventDetails = false;
		}
		return $eventDetails;
	};

